use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

/// nodesconf.json 中的测站配置
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, Default)]
#[serde(default, rename_all = "camelCase")]
pub struct NodeConf {
    pub alias: String,
    pub altitude: f64,
    #[serde(alias = "boardId")]
    pub boardid: i32,
    #[serde(rename = "biasnorth", alias = "biasNorth")]
    pub bias_north: f64,
    pub channels: i32,
    pub codesize: i32,
    #[serde(default)]
    pub devtype: Option<String>,
    #[serde(default, alias = "cvtcoef")]
    pub cvt_coef: Option<f64>,
    #[serde(default)]
    pub ipaddr: Option<String>,
    pub latitude: f64,
    pub longitude: f64,
    pub pitch: f64,
    pub radius: f64,
    #[serde(default)]
    pub ranges: Vec<f64>,
    #[serde(default)]
    pub sensitivity: Vec<f64>,
    #[serde(default, alias = "smprate")]
    pub smprate: i32,
    #[serde(default, rename = "waveType", alias = "wave_type")]
    pub wave_type: String,
    #[serde(default)]
    pub wamplify: i32,
    #[serde(default)]
    pub zamplify: i32,
}

#[allow(dead_code)]
impl NodeConf {
    pub fn ipaddr_str(&self) -> &str {
        self.ipaddr.as_deref().unwrap_or_default()
    }

    pub fn depth(&self) -> usize {
        match self.codesize {
            1 => 8,
            2 => 16,
            3 => 24,
            4 => 32,
            _ => 24,
        }
    }
}
